home *** CD-ROM | disk | FTP | other *** search
/ EuroCD 3 / EuroCD 3.iso / Games / Doom / ADoom-0.8 / ADoom_src / mmu.s < prev    next >
Text File  |  1998-06-24  |  3KB  |  165 lines

  1.         mc68040
  2.         multipass
  3.     if (_eval(DEBUG)&$8000)
  4.         debug    on,lattice4
  5.     endc
  6.         super
  7. *
  8. *   mmu.s - 68040/68060 MMU control functions
  9. *   Copyright (C) 1997 Aki Laukkanen
  10. *
  11.  
  12.         XDEF    _mmu_mark
  13.  
  14. ;        include "exec/types.i"
  15. ;        include "exec/memory.i"
  16. ;        include "lvo/exec_lib.i"
  17.         include "mmu.i"
  18.  
  19.     IFND    TRUE
  20. TRUE EQU    1
  21.     ENDC
  22.  
  23.     IFND    FALSE
  24. FALSE EQU   0
  25.     ENDC
  26.  
  27. *
  28. *   FUNCTION
  29. *       UBYTE __asm mmu_mark (register __a0 UBYTE *start,
  30. *                             register __d0 ULONG length,
  31. *                             register __d1 ULONG cm,
  32. *                             register __a6 struct ExecBase *SysBase);
  33. *
  34. *   SYNOPSIS
  35. *       Changes the cache mode for the specified memory area. This
  36. *       area  must be aligned by 4kB and be multiple of 4kB in size.
  37. *
  38. *   RESULT
  39. *       Returns the old cache mode for the memory area.
  40. *
  41. *   NOTES
  42. *       Works only after setpatch has been issued and in such
  43. *       systems where 68040.library/68060.library is correctly
  44. *       installed.
  45. *
  46.  
  47. _mmu_mark
  48.         movem.l    d2/d3/d7/a2/a4/a6,-(sp)
  49.  
  50.         move.l    a1,a4
  51.         movem.l    d0/d1/a0,-(sp)
  52.         jsr    (_LVOSuperState,a6)
  53.         movec    tc,d3            ; translation code register
  54.         movec    urp,d2            ; user root pointer
  55.         jsr    (_LVOUserState,a6)
  56.         movem.l    (sp)+,d0/d1/a0
  57.  
  58.         btst    #TCB_E,d3
  59.         beq    .error
  60.         btst    #TCB_P,d3
  61.         bne    .error
  62.  
  63.         move.l    d1,-(sp)
  64.         move.l    d0,d1
  65.  
  66.         lsr.l    #8,d0
  67.         lsr.l    #4,d0
  68.  
  69.         move.l    a0,a1
  70.  
  71.         and.w    #$fff,d1
  72.         beq.s    .skip_a
  73.         addq.l    #1,d0
  74. .skip_a
  75.         move.l    (sp)+,d1
  76.         subq.l    #1,d0
  77.         move.l    d0,d7
  78.  
  79. ; a1 - chunkybuffer
  80. ; d7 - counter
  81. ; d2 - urp
  82. ; d1 - cache mode
  83.  
  84. .loop
  85.         move.l    d2,-(sp)
  86.         move.l    a1,d0
  87.         rol.l    #8,d0
  88.         lsl.l    #1,d0
  89.         and.w    #%1111111000000000,d2
  90.         and.w    #%0000000111111100,d0
  91.         or.w    d0,d2
  92.         move.l    d2,a2
  93.         move.l    (a2),d2
  94.         btst    #TDB_UDT0,d2
  95.         beq    .skip            ; if 0
  96.         btst    #TDB_UDT1,d2        ; if 1
  97.         beq    .end
  98.         bra    .skip2
  99. .skip
  100.         btst    #TDB_UDT1,d2
  101.         bne    .end
  102. .skip2
  103.         move.l    a1,d0
  104.         lsr.l    #8,d0
  105.         lsr.l    #8,d0
  106.         and.w    #%1111111000000000,d2
  107.         and.w    #%0000000111111100,d0
  108.         or.w    d0,d2
  109.         move.l    d2,a2
  110.         move.l    (a2),d2
  111.         btst    #TDB_UDT0,d2
  112.         beq    .skip1            ; if 0
  113.         btst    #TDB_UDT1,d2        ; if 1
  114.         beq    .end
  115.         bra    .skip3
  116. .skip1
  117.         btst    #TDB_UDT1,d2
  118.         bne    .end
  119. .skip3
  120.         move.l    a1,d0
  121.         lsr.l    #8,d0
  122.         lsr.l    #2,d0
  123.         and.w    #%1111111100000000,d2
  124.         and.w    #%0000000011111100,d0
  125.         or.w    d0,d2
  126.  
  127.         move.l    d2,a2
  128.         btst    #PDB_PDT1,(3,a2)
  129.         bne    .skip4
  130.         btst    #PDB_PDT0,(3,a2)
  131.         beq    .end
  132.         bra    .skip5
  133. .skip4
  134.         btst    #PDB_PDT0,(3,a2)
  135.         beq    .indirect
  136. .skip5
  137.         move.b    (3,a2),d3
  138.         and.b    #~CM_MASK,(3,a2)
  139.         or.b    d1,(3,a2)
  140.  
  141. .indirect
  142.         lea    (4096,a1),a1
  143.  
  144.         move.l    (sp)+,d2
  145.         dbf    d7,.loop
  146.  
  147.         and.b    #CM_MASK,d3
  148.         jsr    (_LVOSuperState,a6)
  149.         pflusha
  150.         jsr    (_LVOUserState,a6)
  151.  
  152.         moveq    #0,d0
  153.         move.b    d3,d0
  154.  
  155.         movem.l    (sp)+,d2/d3/d7/a2/a4/a6
  156.         rts
  157. .end
  158.         move.l    (sp)+,d2
  159. .error
  160.         movem.l    (sp)+,d2/d3/d7/a2/a4/a6
  161.         moveq    #0,d0
  162.         rts
  163.  
  164.         end
  165.